<?php
namespace app\promotion\controller\agent;
use app\common\controller\BaseController;
use app\common\service\agent\PromotionAccountService;
use app\common\validate\agent\PromotionAccountValidate;
use hg\apidoc\annotation as Apidoc;
/**
 * @Apidoc\Title("推广员银行卡管理")
 * @Apidoc\Group("agent")
 * @Apidoc\Sort("250")
 */
class PromotionAccount extends BaseController
{
    /**
    * @Apidoc\Title("推广员银行卡管理列表")
    * @Apidoc\Query(ref="pagingQuery")
    * @Apidoc\Query(ref="sortQuery")
    * @Apidoc\Query(ref="searchQuery")
    * @Apidoc\Query(ref="dateQuery")
    * @Apidoc\Returned(ref="expsReturn")
    * @Apidoc\Returned(ref="pagingReturn")
    * @Apidoc\Returned("list", type="array", desc="推广员银行卡管理列表", children={
    *   @Apidoc\Returned(ref="app\common\model\PromotionAccountModel", field="id,is_disable,create_time,update_time,promotion_user_id,type,name,bank,bank_branch,card_no,alipay_account,remark,sort")
    * })
    */
    public function list()
    {
        $where = $this->where(where_delete());
        $data = PromotionAccountService::list($where, $this->page(), $this->limit(), $this->order());
        return success($data);
    }
    /**
    * @Apidoc\Title("推广员银行卡管理信息")
    * @Apidoc\Query(ref="app\common\model\PromotionAccountModel", field="id")
    * @Apidoc\Returned(ref="app\common\model\PromotionAccountModel")
    */
    public function info()
    {
        $param = $this->params(['id/d' => '']);
        validate(PromotionAccountValidate::class)->scene('info')->check($param);
        $data = PromotionAccountService::info($param['id']);
        return success($data);
    }
    /**
    * @Apidoc\Title("推广员银行卡管理添加")
    * @Apidoc\Method("POST")
    * @Apidoc\Param(ref="app\common\model\PromotionAccountModel", field="is_disable,promotion_user_id,type,name,bank,bank_branch,card_no,alipay_account,remark,sort")
    */
    public function add()
    {
        $param = $this->params(PromotionAccountService::$edit_field);
        validate(PromotionAccountValidate::class)->scene('add'.$param['type'])->check($param);
        $param['promotion_user_id'] = promotion_user_id();
        $data = PromotionAccountService::add($param);
        return success($data);
    }
    /**
    * @Apidoc\Title("推广员银行卡管理修改")
    * @Apidoc\Method("POST")
    * @Apidoc\Param(ref="app\common\model\PromotionAccountModel", field="id,is_disable,promotion_user_id,type,name,bank,bank_branch,card_no,alipay_account,remark,sort")
    */
    public function edit()
    {
        $param = $this->params(PromotionAccountService::$edit_field);
        validate(PromotionAccountValidate::class)->scene('edit'.$param['type'])->check($param);
        $data = PromotionAccountService::edit($param['id'], $param);
        return success($data);
    }
    /**
    * @Apidoc\Title("推广员银行卡管理删除")
    * @Apidoc\Method("POST")
    * @Apidoc\Param(ref="idsParam")
    */
    public function dele()
    {
        $param = $this->params(['ids/a' => []]);
        validate(PromotionAccountValidate::class)->scene('dele')->check($param);
        $data = PromotionAccountService::dele($param['ids']);
        return success($data);
    }
    /**
     * @Apidoc\Title("推广员银行卡管理禁用")
     * @Apidoc\Method("POST")
     * @Apidoc\Param(ref="idsParam")
     * @Apidoc\Param(ref="app\common\model\PromotionAccountModel", field="is_disable")
     */
    public function disable()
    {
        $param = $this->params(['ids/a' => [], 'is_disable/d' => 0]);
        validate(PromotionAccountValidate::class)->scene('disable')->check($param);
        $data = PromotionAccountService::edit($param['ids'], $param);
        return success($data);
    }
}
